package com.hunliji.monitor.manager.config;

import com.lark.project.core.Config;
import com.lark.project.core.token.AccessTokenType;
import com.lark.project.service.view.ViewService;
import com.lark.project.service.view.ViewServiceImpl;
import com.lark.project.service.workitem.WorkItemService;
import com.lark.project.service.workitem.WorkItemServiceImpl;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Data
@RefreshScope
public class FeishuProjectConfig {

    @Value("${feishu.plugin.baseUrl:https://project.feishu.cn}")
    private String baseUrl;

    @Value("${feishu.plugin.pluginId:MII_65AF286F93514001}")
    private String pluginId;

    @Value("${feishu.plugin.pluginSecret:14C4EE6C3179CC54C36D5E981575B067}")
    private String pluginSecret;

    @Value("${feishu.plugin.userKey:7316245780774322178}")
    private String userKey;

    @Bean("feishuPluginConfig")
    public Config config(){
        Config config = new Config();
        config.setBaseUrl(baseUrl);
        config.setPluginID(pluginId);
        config.setPluginSecret(pluginSecret);

        config.setAccessTokenType(AccessTokenType.AccessTokenTypePlugin);
        return config;
    }

    @Bean
    public WorkItemService workItemService(Config config){
        return new WorkItemServiceImpl(config);
    }

    @Bean
    public ViewService viewService(Config config){
        return new ViewServiceImpl(config);
    }
}
